﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApC3DUtils
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System.Collections.ObjectModel;
using System.Reflection;
using System.Resources;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands;

internal class CApC3DUtils
{
  internal static string U3DExtension = ".u3d";
  internal static string PRCExtension = ".prc";
  internal static string DataFileExtension = ".xml";
  internal static string JSExtension = ".js";
  private static ResourceManager _ResMgr = (ResourceManager) null;

  internal static ResourceManager GetResourceManager()
  {
    if (CApC3DUtils._ResMgr == null)
      CApC3DUtils._ResMgr = new ResourceManager("DnProcessSimulateCommands.StringTable", Assembly.GetExecutingAssembly());
    return CApC3DUtils._ResMgr;
  }

  public static TxObjectList GetLoadedPMIs()
  {
    TxTypeFilter txTypeFilter = new TxTypeFilter();
    txTypeFilter.AddIncludedType(typeof (TxComponent));
    TxObjectList allDescendants = TxApplication.ActiveDocument.PhysicalRoot.GetAllDescendants((ITxTypeFilter) txTypeFilter);
    TxObjectList loadedPmIs = new TxObjectList();
    foreach (TxComponent component in (Collection<ITxObject>) allDescendants)
    {
      TxObjectList componentPmIs = CApC3DUtils.GetComponentPMIs(component);
      if (((Collection<ITxObject>) componentPmIs).Count != 0)
        ((TxObjectList<ITxObject>) loadedPmIs).Append((TxObjectList<ITxObject>) componentPmIs);
    }
    return loadedPmIs;
  }

  public static string GetObjectId(ITxObject obj)
  {
    return TxEngineeringDataInternal.GetIdStringFromObject(obj);
  }

  public static string GetObjectId(ITxObject obj, string objAppearenceIdx)
  {
    string objectId = TxEngineeringDataInternal.GetIdStringFromObject(obj);
    if (objAppearenceIdx != "")
      objectId = $"{objectId}_{objAppearenceIdx}";
    return objectId;
  }

  public static bool IsObjOfAppearanceType(ITxObject obj) => obj is TxPmi || obj is TxNote;

  private static TxObjectList GetComponentPMIs(TxComponent component)
  {
    TxObjectList allDescendants = component.GetAllDescendants((ITxTypeFilter) new TxNoTypeFilter());
    TxObjectList componentPmIs = new TxObjectList();
    foreach (ITxObject itxObject in (Collection<ITxObject>) allDescendants)
    {
      if (TxObjectEx.HasPMIType(itxObject))
        ((Collection<ITxObject>) componentPmIs).Add(itxObject);
    }
    return componentPmIs;
  }
}
